/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            buyGoldSendParkingInfo: {
                spId: '',
                actualPrice: '0',
                couponName: '0',
                stock: '0',
                giftsCostMoney: '1',
                licensePlate: '',
                tel: '',
                shopId: vc.getCurrentCommunity().shopId,
                showRefresh: false
            }
        },
        _initMethod: function () {
            $that.buyGoldSendParkingInfo.spId = vc.getParam('spId');
            $that._listProducts(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('buyGoldSendParking', 'listProduct', function (_param) {
                $that.buyGoldSendParkingInfo.componentShow = 'buyGoldSendParking';
                $that._listProducts(DEFAULT_PAGE, DEFAULT_ROWS);
            });
        },
        methods: {
            _listProducts: function (_page, _rows) {
                var param = {
                    params: {
                        page: 1,
                        spId: $that.buyGoldSendParkingInfo.spId,
                        row: 1
                    }
                };
                //发送get请求
                vc.http.apiGet('couponShopPool.listCouponShopPool',
                    param,
                    function (json, res) {
                        let _buyGoldSendParkingInfo = JSON.parse(json);
                        vc.copyObject(_buyGoldSendParkingInfo.data[0], $that.buyGoldSendParkingInfo);
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _closebuyGoldSendParking: function () {
                vc.goBack();
            },
            _changeGoldCount: function () {
               
                if($that.buyGoldSendParkingInfo.stock - $that.buyGoldSendParkingInfo.giftsCostMoney  < 0){
                    vc.toast("库存不足，请先购买优惠卷！");
                    return;
                }
            },
            _tobuyGoldSendParking: function () {
                if($that.buyGoldSendParkingInfo.stock - $that.buyGoldSendParkingInfo.giftsCostMoney  < 0){
                    vc.toast("库存不足，请先购买优惠卷！");
                    return;
                }
            
                vc.http.apiPost(
                    '/cart/saveSendParking',
                    JSON.stringify($that.buyGoldSendParkingInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast(_json.msg);
                            $that._closebuyGoldSendParking();
                            return;
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _finishScanQrCode: function () {
                $that._closebuyGoldSendParking();
            }
        }
    });
})(window.vc);
